package nc.bs.ntb.analyse;
import java.io.IOException;
import java.util.InvalidPropertiesFormatException;

import nc.tb.analyse.pub.AnalysePubCTL;
import nc.tb.chartreport.IChartRptConst;
import nc.tb.ctl.SheetObjectCTL;
import nc.tb.cube.CubeView;
import nc.tb.pub.layout.IGridCellParser;
import nc.tb.pub.util.NtbLogger;
import nc.tb.pub.util.StringProperties;

public class HtmlGridCellParser implements IGridCellParser {

	public Object getContentValue(Object contentStr) {
		if (contentStr != null && contentStr.toString().length() > 0) {
			StringProperties sp = new StringProperties();
			try {
				sp.loadFromXML(contentStr.toString());
				Object pk_ds = sp.get(IChartRptConst.DATASET);

				if (pk_ds != null) {
					CubeView ds = SheetObjectCTL.getCubeViewByPk (pk_ds.toString());
					return AnalysePubCTL.getAnalyseUIModel(ds,null,true);
				}
			} catch (InvalidPropertiesFormatException e) {
				NtbLogger.error(e);
			} catch (IOException e) {
				NtbLogger.error(e);
			} catch (Exception e) {
				NtbLogger.error(e);
			}
				
		}
		return null;
	}
	

	public String getNameFromUserObject(Object contentStr) {
		if (contentStr != null && contentStr.toString().length() > 0) {
			StringProperties sp = new StringProperties();
			try {
				sp.loadFromXML(contentStr.toString());
				return sp.get(IChartRptConst.CELL_NAME) == null ? null : sp.get(IChartRptConst.CELL_NAME).toString();
			} catch (IOException e) {
				NtbLogger.error(e);
			} catch (Exception e) {
				NtbLogger.error(e);
			}
		}
		return null;
	}

}
